<?php
/**
 * This is areas/admin_list template file. 
 *
 * @copyright     Copyright 2008-2010, LilCake.net
 * @link          http://lilcake.net LilCake.net
 * @package       lil
 * @subpackage    lil.views.areas
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
	$pagination_url = Router::getParam('pass');
	
	$area_list = array(
		'title_for_layout' => __d('lil', 'Select your Area'),
		'menu' => array(
			'pre'   => '',
			'post'  => '',
			'items' => array(
				'noarea' => array(
					'title' => __d('lil', 'Clear current Area', true),
					'visible' => true,
					'url' => array(
						'admin'      => true,
						'plugin'     => 'lil',
						'controller' => 'areas',
						'action'     => 'select',
					)
				)
			)
		),
		'table' => array(
			'pre' => '<div class="index">' . PHP_EOL,
			'post' => '</div>',
			'element' => array(
				'parameters' => array(
					'cellspacing' => 0,
					'cellpadding' => 0,
					'id'          => 'AdminAreasList',
					'class'       => 'index'
				),
			)
		)
	);

	$area_list['table']['element']['head'] = array(
		'parameters' => array(),
		'rows' => array(
			0 => array(
				'parameters' => array(),
				'columns' => array(
					'name' => array(
						'parameters' => array('class' => 'left'),
						'html'       => __d('lil', 'Name'),
					),
					Configure::read('Lil.areaSlugField') => array(
						'parameters' => array('class' => 'left'),
						'html'       => __d('lil', 'Slug'),
					),
				)
			)
		)
	);
	
	// table body values
	$area_list['table']['element']['body']['rows'] = array();
	if (empty($data)) {
		$area_list['table']['element']['body']['rows'][0] = array(
			'parameters' => array(),
			'columns' => array(
				0 => array(
					'parameters' => array('colspan' => '2', 'class' => 'light'),
					'html'       => __d('lil', 'No areas that match your criteria.')
				)
			),
		);
	} else {
		$i = 0;
		foreach($data as $item) {
			$area_list['table']['element']['body']['rows'][$i] = array(
				'post' => $item,
				'parameters' => ($i++ % 2 == 0) ? array() : array('class' => 'altrow'),
				'columns' => array(
					'name' => array(
						'parameters' => array(),
						'html'       => $this->Html->link(
							$item['Area'][Configure::read('Lil.areaDisplayField')],
							array(
								'admin'      => true,
								'controller' => 'areas',
								'action'     => 'select',
								$item['Area']['id']
							),
							array(
								'class' => 'big'
							)
						)
					),
					Configure::read('Lil.areaSlugField') => array(
						'parameters' => array(),
						'html'       => $this->Html->clean($item['Area'][Configure::read('Lil.areaSlugField')])
					),
				)
			);
			

		}
	}
	
	$area_list['table']['element']['foot'] = array(
		'parameters' => array(),
		'rows' => array(
			/*0 => array(
				'parameters' => array(),
				'columns' => array(
					'paginator' => array(
						'parameters' => array('colspan' => '2', 'class' => 'paging'),
						'html'       => $this->Lil->paginator()
					),
				)
			)*/
		)
	);
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// call plugin handlers
	App::uses('LilPluginRegistry', 'Lil.Lil'); $registry = LilPluginRegistry::getInstance();
	$area_list = $registry->callPluginHandlers($this, 'admin_list_areas', $area_list);
	
	$this->set('title_for_layout', $area_list['title_for_layout']);
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// form display begins
	echo $area_list['menu']['pre'];
	$this->set('main_menu', $area_list['menu']['items']);
	/*foreach ($area_list['actions']['lines'] as $name => $line) {
		if (is_array($line) && !empty($line['class'])) {
			$parameters = array();
			if (!empty($line['parameters'])) {
				$parameters = (array)$line['parameters'];
			}
			echo call_user_func_array(array($line['class'], $line['method']), $parameters);
		} else {
			echo $line;
		}
	}*/
	echo $area_list['menu']['post'] . PHP_EOL;
	
	echo $area_list['table']['pre'];
	echo '<table';
	foreach ($area_list['table']['element']['parameters'] as $key => $param) {
		echo ' ' . $key . '="' . $param . '"';
	}
	echo '>' . PHP_EOL;
	
	// display thead
	echo '<thead';
	foreach ($area_list['table']['element']['head']['parameters'] as $key => $param) {
		echo ' ' . $key . '="' . $param . '"';
	}
	echo '>' . PHP_EOL;
	
	foreach ($area_list['table']['element']['head']['rows'] as $row) {
			echo '<tr';
			foreach ($row['parameters'] as $key => $param) {
				echo ' ' . $key . '="' . $param . '"';
			}
			echo '>' . PHP_EOL;
			
			foreach ($row['columns'] as $col) {
				echo '<th';
				foreach ($col['parameters'] as $key => $param) {
					echo ' ' . $key . '="' . $param . '"';
				}
				echo '>' . PHP_EOL;
				
				echo $col['html'];
				echo '</th>' . PHP_EOL;
			}
			
			echo '</tr>' . PHP_EOL;
	}
	echo '</thead>' . PHP_EOL;
	
	// display body
	foreach ($area_list['table']['element']['body']['rows'] as $row) {
		echo '<tr';
		foreach ($row['parameters'] as $key => $param) {
			echo ' ' . $key . '="' . $param . '"';
		}
		echo '>' . PHP_EOL;
		
		foreach ($row['columns'] as $col) {
			echo '<td';
			if (isset($col['parameters'])) {
				foreach ((array)$col['parameters'] as $key => $param) {
					echo ' ' . $key . '="' . $param . '"';
				}
			}
			echo '>' . PHP_EOL;
			echo $col['html'];
			echo '</td>' . PHP_EOL;
		}
		
		echo '</tr>' . PHP_EOL;
	}
	
	// display tfoot
	echo '<tfoot';
	foreach ($area_list['table']['element']['foot']['parameters'] as $key => $param) {
		echo ' ' . $key . '="' . $param . '"';
	}
	echo '>' . PHP_EOL;
	
	foreach ($area_list['table']['element']['foot']['rows'] as $row) {
			echo '<tr';
			foreach ($row['parameters'] as $key => $param) {
				echo ' ' . $key . '="' . $param . '"';
			}
			echo '>' . PHP_EOL;
			
			foreach ($row['columns'] as $col) {
				echo '<th';
				foreach ($col['parameters'] as $key => $param) {
					echo ' ' . $key . '="' . $param . '"';
				}
				echo '>' . PHP_EOL;
				echo $col['html'];
				echo '</th>' . PHP_EOL;
			}
			
			echo '</tr>' . PHP_EOL;
	}
	echo '</tfoot>' . PHP_EOL;
	
	echo '</table>' . PHP_EOL;
	echo $area_list['table']['post'];
?>